package GUIadapter;

import java.util.List;

import javax.swing.table.AbstractTableModel;

import ModelLayer.Order;
import ModelLayer.PartOrder;
import ModelLayer.SaleOrder;

@SuppressWarnings("serial")
public class OrderModel extends AbstractTableModel
{
	private final String[] columnHeader= {"Navn", "Antal", "Pris"};
	
	private List<SaleOrder> saleorderList;

	public OrderModel(List<SaleOrder> saleorderList)
	{
		this.saleorderList = saleorderList;
	}
	
	@Override
	public String getColumnName(int column)
	{
		// TODO Auto-generated method stub
		return columnHeader[column];
	}

	@Override
	public int getColumnCount()
	{
		// TODO Auto-generated method stub
		return columnHeader.length; //depends on amount of getters for a supplier eg.: "getName()"... very ugly
	}

	@Override
	public int getRowCount()
	{
		// TODO Auto-generated method stub
		return saleorderList.size();
	}

	@Override
	public Object getValueAt(int row, int col)
	{
		// TODO Auto-generated method stub
		SaleOrder saleorder = saleorderList.get(row);
		switch(col)
		{
		case 0:
			return saleorder.getPartOrderList().get(getindex()).getSaleItem().getDescription();
		case 1:
			return saleorder.getPartOrderList().get(getindex()).getAmount();
		case 2:
			return saleorder.getPartOrderList().get(getindex()).calculateSubTotal();
		}
		return null; //should never reach here..!
	}
	
	public int getindex()
	{
		int i = 0;
		for(int index = 0; saleorderList.size() < index; index++)
		{
			i = index;
		}
		return i;
	}
} //end TableSupplierAdapter